package com.jule.miaozhuapc.dao.impl;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.json.JSONObject;
import org.springframework.stereotype.Repository;

import com.jule.miaozhuapc.dao.UserLocationDao;
import com.jule.miaozhuapc.domain.WawaUserLocation;

@Repository
public class UserLocationDAOImpl   implements UserLocationDao{

	private EntityManager em;
	@PersistenceContext
	public void setEm(EntityManager em) {
		this.em = em;
	}
	
	@Override
	public void update(WawaUserLocation location) {
		System.out.println("location " + new JSONObject(location));
		location.setUserId(2L);
		em.persist(location);
		System.out.println(" end " + new JSONObject(location));
	}

	@Override
	public WawaUserLocation findByUserId(Long userId) {
		String hql = "from WawaUserLocation where userId =:userId and isDelete = 0";
		WawaUserLocation wawaUserLocation = em.createQuery(hql, WawaUserLocation.class)
				.setParameter("userId", userId)
				.getSingleResult();
		return wawaUserLocation;
	}

}
